//
//  SimpleAlertView.m
//  ALittleReminder
//
//  Created by George on 11-11-02.
//
//  Changes:
//  Nov.16 2011 Implemented panick butten. (Jason)

#import "MainViewController.h"
#import "SetAlertViewController.h"
#import "passwordViewController.h"
#import "CaretakerViewController.h"
#import "CareTakerAccount.h"
#import "AlertTableController.h"
#import "WhoamIAccount.h"

@implementation MainViewController
@synthesize AddButton;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [self setAddButton:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


- (IBAction)onAddButton:(id)sender {
    SetAlertViewController *openView = [[SetAlertViewController alloc] initWithAlert:nil];
    [self presentModalViewController:openView animated:YES];
}

- (IBAction)onCheckReminder:(id)sender {
    AlertTableController *openView = [[AlertTableController alloc] initWithStyle:UITableViewStylePlain];
    [self presentModalViewController:openView animated:YES];
}


- (IBAction)onCaretakerButton:(id)sender {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docDir = [paths objectAtIndex: 0];
    NSString *docFile = [docDir stringByAppendingPathComponent: @"caretakerInfo.txt"];
    
    NSString *textfromfile = [NSString stringWithContentsOfFile:docFile encoding:NSStringEncodingConversionAllowLossy error:nil];
    
    if([textfromfile length] == 0){
        CareTakerAccount *openView = [[CareTakerAccount alloc] initWithNibName:nil bundle:nil];
        [self presentModalViewController:openView animated:YES];
    }
    else{
        
        CaretakerViewController *openView = [[CaretakerViewController alloc] initWithNibName:nil bundle:nil];
        [self presentModalViewController:openView animated:YES];
    }
}

// Changes the view to the CaretakerViewController when CARETAKER button is clicked


- (IBAction)onWhoButton:(id)sender {
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docDir = [paths objectAtIndex: 0];
    NSString *docFile = [docDir stringByAppendingPathComponent: @"myInfo.txt"];
    
    NSString *textfromfile = [NSString stringWithContentsOfFile:docFile encoding:NSStringEncodingConversionAllowLossy error:nil];
    
    if([textfromfile length] == 0){
        WhoamIAccount *openView = [[WhoamIAccount alloc] initWithNibName:nil bundle:nil];
        [self presentModalViewController:openView animated:YES];
    }
    else{
        
        passwordViewController *openView = [[passwordViewController alloc] initWithNibName:nil bundle:nil];
        [self presentModalViewController:openView animated:YES];
    }

    
}



- (IBAction)onPanic:(id)sender {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:7886816961"]];
}
@end
